package com.ruoyi.eqmonitor.controller;

import java.util.List;

import com.ruoyi.eqmonitor.domain.OptDeviceAlarmProcess;
import com.ruoyi.eqmonitor.service.IOptDeviceAlarmProcessService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备报警处理过程
 * @author ruoyi
 * @date 2022-11-26
 */
@RestController
@RequestMapping("/process")
public class OptDeviceAlarmProcessController extends BaseController{
    
    @Autowired
    private IOptDeviceAlarmProcessService optDeviceAlarmProcessService;

    /**
     * 设备报警处理过程列表
     * @param optDeviceAlarmProcess 设备报警处理过程查询参数
     * @return 表格分页数据对象
     */
    @ApiOperation("设备报警处理过程列表")
    @GetMapping("/list")
    public TableDataInfo<?> list(OptDeviceAlarmProcess optDeviceAlarmProcess){
        startPage();
        List<OptDeviceAlarmProcess> list = optDeviceAlarmProcessService.selectOptDeviceAlarmProcessList(optDeviceAlarmProcess);
        return getDataTable(list);
    }

    /**
     * 根据id查询设备报警处理过程明细
     */
    @ApiOperation("根据id查询设备报警处理过程明细")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(optDeviceAlarmProcessService.selectOptDeviceAlarmProcessById(id));
    }

    /**
     * 新增设备报警处理过程明细
     */
    @ApiOperation("新增设备报警处理过程明细")
    @Log(title = "设备报警处理过程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OptDeviceAlarmProcess optDeviceAlarmProcess){
    	optDeviceAlarmProcess.setCreateTime(new Date());
    	optDeviceAlarmProcess.setCreateBy(SecurityUtils.getUsername());
        return toAjax(optDeviceAlarmProcessService.save(optDeviceAlarmProcess));
    }

    /**
     * 修改设备报警处理过程明细
     */
    @ApiOperation("修改设备报警处理过程明细")
    @PutMapping
    public AjaxResult edit(@RequestBody OptDeviceAlarmProcess optDeviceAlarmProcess){
    	optDeviceAlarmProcess.setUpdateTime(new Date());
    	optDeviceAlarmProcess.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(optDeviceAlarmProcessService.updateById(optDeviceAlarmProcess));
    }

    /**
     * 删除设备报警处理过程明细
     */
    @ApiOperation("删除设备报警处理过程明细")
    @Log(title = "设备报警处理过程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(optDeviceAlarmProcessService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出设备报警处理过程列表
     */
    @ApiOperation("导出设备报警处理过程列表")
    @Log(title = "设备报警处理过程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OptDeviceAlarmProcess optDeviceAlarmProcess){
        List<OptDeviceAlarmProcess> list = optDeviceAlarmProcessService.selectOptDeviceAlarmProcessList(optDeviceAlarmProcess);
        ExcelUtil<OptDeviceAlarmProcess> util = new ExcelUtil<OptDeviceAlarmProcess>(OptDeviceAlarmProcess.class);
        util.exportExcel(response, list, "设备报警处理过程数据");
    }
    
}
